package org.example.videotran.timedTask;

import org.example.videotran.utils.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.example.videotran.exception.AppException;
import org.example.videotran.exception.AppExceptionCodeMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

@Component
public class FileCleanupTask {

    private static final Logger logger = LoggerFactory.getLogger(FileCleanupTask.class);

    @Value("${file.upload-dir}")
    private String cleanupDirectory;

    @Value("${file.output}")
    private String cleanOutPut;

    @Value("${file.cleanup.maxAgeDays:7}")
    private int maxAgeDays;

    /**
     * 每天凌晨2点执行清理
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanupOldFiles() {

        FileUtils.deleteFiles(cleanupDirectory);
        FileUtils.deleteFiles(cleanOutPut);

    }
}